{include file="public/header" /}
<?php error_reporting(E_ALL^E_NOTICE);?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>根据地址查询经纬度</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3&ak=QnLXMv34klIRL0tk1GhHFLjZ"></script>
</head>
<body style="background:#CBE1FF">
<div style="width:100%;margin:auto;">

  要查询的地址：<input id="text_" name="title" type="text"  placeholder="请手动输入地址" style="margin-right:40px;"/>
  查询结果(经纬度)：<input id="jingdu" type="text" name="jingdu" /><input id="weidu" type="text" name="weidu" />
  <input type="button" value="查询坐标" onClick="searchByStationName();"/>

  <input type="submit" onclick="is_ion();" value="提交地址"/>

  <div id="container"
       style="position: absolute;
                margin-top:30px;
                width: 100%;
                height: 590px;
                top: 50;
                border: 1px solid gray;
                overflow:hidden;">
  </div>
</div>
</body>

<!---->
<script type="text/javascript">
  var map = new BMap.Map("container");
  map.centerAndZoom("广州", 12);
  map.enableScrollWheelZoom();    //启用滚轮放大缩小，默认禁用
  map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用

  map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
  map.addControl(new BMap.OverviewMapControl()); //添加默认缩略地图控件
  map.addControl(new BMap.OverviewMapControl({ isOpen: true, anchor: BMAP_ANCHOR_BOTTOM_RIGHT }));   //右下角，打开

  var localSearch = new BMap.LocalSearch(map);
  localSearch.enableAutoViewport(); //允许自动调节窗体大小
  function searchByStationName() {
    map.clearOverlays();//清空原来的标注
    var keyword = document.getElementById("text_").value;
    localSearch.setSearchCompleteCallback(function (searchResult) {
      var poi = searchResult.getPoi(0);
      document.getElementById("jingdu").value = poi.point.lng;
      document.getElementById("weidu").value =  poi.point.lat;
      map.centerAndZoom(poi.point, 13);
      var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));  // 创建标注，为要查询的地方对应的经纬度
      map.addOverlay(marker);


      document.getElementById('text_').value = poi.address||document.getElementById('text_').value;
      var content = document.getElementById("text_").value + "<br/><br/>经度：" + poi.point.lng + "<br/>纬度：" + poi.point.lat;
      var infoWindow = new BMap.InfoWindow("<p style='font-size:14px;'>" + content + "</p>");
      marker.addEventListener("click", function () { this.openInfoWindow(infoWindow); });
      // marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
    });
    localSearch.search(keyword);
  }



  function is_ion(){
    var text_ = $('#text_').val();

    var jingdu = $('#jingdu').val();
    var weidu = $('#weidu').val();

    if(!text_){
      alert('请在输入框输入地址');
      return ;
    }
    if(!jingdu){
      alert('请点击查询坐标按钮');
      return ;
    }
    if(!weidu){
      alert('请点击查询坐标按钮');
      return ;
    }

    var search=window.location.search;
    search =  search.split('&');
    var shopid = '';
    for(var i = 0; i<search.length;i++){
      if(search[i].indexOf('shopid')!=-1){
        shopid = search[i].split('=')[1]||'';

      }
    };
    var action = '{$action}';
    var id = '{$id}';
    window.location.href="{:url('admin/cluster/"+action+"')}?url=-1&id="+id+"&longitude="+jingdu+'&latitude='+weidu+'&city='+text_;
  }
</script>
</html>